layui.config({
    base: SCOPE.static + '/admin/js/module/'
}).extend({
    dialog: 'dialog',
    load: 'load',
    common: 'common'
});

layui.use(['form', 'jquery', 'laydate', 'layer', 'laypage', 'dialog','common','tool'], function () {
    var form = layui.form(),
        layer = layui.layer,
        $ = layui.jquery,
        laypage = layui.laypage,
        laydate = layui.laydate,
        common = layui.common,
        tool = layui.tool,
        dialog = layui.dialog;

    //获取当前iframe的name值
    var iframeObj = $(window.frameElement).attr('name');
    //全选
    form.on('checkbox(allChoose)', function (data) {
        var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]');
        child.each(function (index, item) {
            item.checked = data.elem.checked;
        });
        form.render('checkbox');
    });
    form.render();
    //删除
    $('.del-btn').on('click', function () {
        var id=$(this).attr('data-id');
        common.del(SCOPE.del,id);
    })

    //提示
    $('.addBtn').click(function () {

        //将iframeObj传递给父级窗口
        parent.page("生活分类添加", SCOPE.add, iframeObj, w = "700px", h = "330px");
        return false;

    }).mouseenter(function () {

        common.tips('添加', '.addBtn');

    })


    //排序
    $('.listOrderBtn').click(function () {

        common.listOrderAll(SCOPE.listOrderAll,'您确定要进行排序吗？');
        return false;

    }).mouseenter(function () {

        common.tips('排序', '.listOrderBtn');

    })



    //批量删除
    $('.delBtn').click(function () {

        common.delAll(SCOPE.delAll,'您确定要批量删除栏目吗');
        return false;

    }).mouseenter(function (e) {

        common.tips('删除', '.delBtn');

    })





    //修改状态
    $('#category-table-list').on('click', '.category-list-status', function () {
        var That = $(this);
        var status = That.attr('data-status');
        var id = That.parent().attr('data-id');
        if (status == 1) {
            $.post(SCOPE.status, {status: 2, id: id}, function (res) {
                if (res.status == 1) {
                    layer.msg(res.message);
                    That.removeClass('layui-btn-normal').addClass('layui-btn-warm').html('待审').attr('data-status', 2);
                } else {
                    layer.msg(res.message);
                }
            }, 'json');
            $(document).ajaxError(function() {
                layer.msg('网络请求失败！');
            });

        } else if (status == 2) {
            $.post(SCOPE.status, {status: 1, id: id}, function (res) {
                if (res.status == 1) {
                    layer.msg(res.message);
                    That.removeClass('layui-btn-warm').addClass('layui-btn-normal').html('正常').attr('data-status', 1);
                } else {
                    layer.msg(res.message);
                }
            }, 'json');
            $(document).ajaxError(function() {
                layer.msg('网络请求失败！');
            });

        } else if (status == 0) {

        }
    })
    //编辑栏目
    $('#category-table-list').on('click', '.edit-btn', function () {
        var That = $(this);
        var id = That.attr('data-id');

        //将iframeObj传递给父级窗口
        parent.page("生活分类添加", SCOPE.edit + "?id=" + id, iframeObj, w = "700px", h = "330px");
    })
});

